package com.jz.community.moduleshoppingguide.neighbor.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.neighbor.bean.CircleMessageBean;
import com.jz.community.moduleshoppingguide.neighbor.bean.NearCircleListBean;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModel;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModelImp;
import com.jz.community.moduleshoppingguide.neighbor.ui.NeighborNearView;

public class NeighborNearPresenter extends BaseLifeCyclePresent<NeighborNearView.View> implements NeighborNearView.Presenter {

    private NeighborNearView.View view;
    private NeighborModel neighborModel;

    public NeighborNearPresenter(NeighborNearView.View view) {
        this.view = view;
        this.neighborModel = new NeighborModelImp(view.getContext());
    }

    @Override
    public void initUserNeighbor() {
        neighborModel.initUserNeighbor(new OnLoadListener<CircleMessageBean>() {
            @Override
            public void onSuccess(CircleMessageBean circleMessageBean) {
                view.isAddCircle(circleMessageBean);

            }

            @Override
            public void onFail(String msg, int code) {
                if (code == 404) {
                    view.noAddCircle();
                } else {
                    view.showError(msg);
                }

            }
        });

    }

    @Override
    public void initNearNeighbor(String lat, String lon, int page, int size) {
        neighborModel.initNearNeighbor(lat, lon, page, size, new OnLoadListener<NearCircleListBean>() {
            @Override
            public void onSuccess(NearCircleListBean nearCircleListBean) {
                view.setNeighborNearData(nearCircleListBean);

            }

            @Override
            public void onFail(String msg, int code) {
                view.showError(msg);

            }
        });

    }

    @Override
    public void addNeighbor(String circleId) {
        neighborModel.addNeighbor(circleId, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.addNeighborSuccess(circleId);
            }

            @Override
            public void onFail(String msg, int code) {
                view.addNeighborFail(msg);

            }
        });

    }
}
